<%@page import="multiface.promonet.filter.MatchPK"%>
<%@page import="org.json.simple.JSONObject"%>
<%@page import="org.json.simple.JSONArray"%>
<%@page import="org.json.simple.parser.JSONParser"%>
<%@page import="com.sun.org.apache.bcel.internal.generic.AALOAD"%>
<%@page import="multiface.promonet.filter.Match"%>
<%@page import="javax.persistence.EntityManager"%>
<%@page import="javax.persistence.EntityManagerFactory"%>
<%@page import="javax.persistence.Persistence"%>
<%@page import="multiface.web.util.Crypto"%>
<%@page import="it.sauronsoftware.base64.Base64"%>
<%
    String DATA = request.getParameter("DATA");

    long t1 = System.nanoTime();


    EntityManagerFactory emf = Persistence.createEntityManagerFactory("WinAppPU");
    EntityManager em = emf.createEntityManager();



    out.print("<br>DATA : " + (Base64.decode(DATA)));
    out.print("<br>DATA : " + Crypto.decrypt(Base64.decode(DATA)));

    JSONParser parser = new JSONParser();

    JSONObject obj = (JSONObject) parser.parse(Crypto.decrypt(Base64.decode(DATA)));

    out.print("<br>ID_user: " + obj.get("id_user"));


    Match m = new Match();
    
    m.setPunti(Integer.parseInt(obj.get("point").toString()));
    MatchPK pk = new MatchPK();
    pk.setIduser(Long.parseLong(obj.get("id_user").toString()));
    pk.setTimer(Long.parseLong(obj.get("time").toString()));
    m.setMatchPK(pk);
    m.setAzione(2);
    m.setGioco(32);
    
    em.getTransaction().begin();
    em.persist(m);
    em.getTransaction().commit();


    em.close();
    emf.close();

    long t2 = System.nanoTime();

    out.print("<br>" + (t2 - t1) + " ns.");

%>